<?php
/*
 +----------------------------------------------------------------------
 + Title        : ApiIdempotent 控制器
 + Author       : Randy_chen
 + Version      : V1.0.0.1
 + Initial-Time : 2020/5/6 11:14
 + Last-time    : 2020/5/6 11:14+ 86187
 + Desc         : ApiIdempotent
 +----------------------------------------------------------------------
*/


namespace myAnnotation\rules;


use think\exception\HttpResponseException;

class ApiIdempotentRule {
    function run(\myAnnotation\Annotation\ApiIdempotent $apiIdempotent){
        //接口幂等性注解
        $transId = input('transId');
        $key = $apiIdempotent->key . $transId;
        request()->setApiKey($key);
        if ($data = cache($key)) {
            throw new HttpResponseException(json($data));
        } else {
            $data['code'] = 1;
            $data['msg'] = '处理中';
            $data['expire'] = $apiIdempotent->expire;
            $data['status'] = 0;
            cache($key, $data , $apiIdempotent->expire);
        }
    }
}